﻿using System;

namespace Glue.Internals.Verification
{
    internal class ConvertibleRandomValues
    {
        private readonly Randomizers randomizers;

        internal ConvertibleRandomValues(Randomizers randomizers)
        {
            this.randomizers = randomizers;
        }

        public object GetRandomValue(Type ofThisType, Type convertibleToThisType)
        {
            if (ofThisType == convertibleToThisType)
                return randomizers.GetRandomValue(ofThisType);
            
            if (ofThisType == typeof(String))
                return randomizers.GetRandomValue(convertibleToThisType).ToString();

            if (ofThisType == typeof(long) &&  (convertibleToThisType == typeof(int) || convertibleToThisType == typeof(short)))
                return Convert.ToInt64(randomizers.GetRandomValue(typeof (short)));
            if (ofThisType == typeof(int) &&  convertibleToThisType == typeof(short))
                return Convert.ToInt32(randomizers.GetRandomValue(typeof (short)));

            return randomizers.GetRandomValue(ofThisType);
        }
    }
}
